import pymysql

conn = pymysql.connect(host="127.0.0.1", port=3306, db="ds0", user="root", password="111111")

# 创建游标对象
cursor = conn.cursor()

data = [(1, "Tom", 27, "浙江杭州"), (2, "Lily", 25, "上海")]
sql = """
insert into user(id,user_name,age,address) values(%s,%s,%s,%s)
"""
try:
    # 执行sql，插入多条记录
    cursor.executemany(sql, data)
    conn.commit()
except BaseException as e:
    print("发生回滚", e)
    conn.rollback()

# 关闭连接
conn.close()
